﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LeMigue.TeamPortal.Base.Biz.Interface;
using LeMigue.Scrum.Iterface.Model;

namespace LeMigue.TeamPortal.Base.Biz.Implement
{
    public class MergeBiz : IMergeBiz
    {
        public T Merge<T>(T origem, T destino, string[] propertyCheck) where T : ScrumItem
        {
            bool save = false;

            foreach (string property in propertyCheck)
            {
                object valorOrigem = origem.GetType().GetProperty(property).GetValue(origem, null);
                object valorDestino = destino.GetType().GetProperty(property).GetValue(destino, null);
                if (valorOrigem != null && !valorOrigem.Equals(valorDestino))
                {
                    destino.GetType().GetProperty(property).SetValue(destino, valorOrigem, null);
                    save = true;
                }
            }

            if (save)
                return destino;
            else
                return null;
        }
    }
}
